<script setup lang="ts">
import { useChartAutoResize } from '@/mixins/MixinChartAutoResize'
import type { VChartInstance } from '@/types'
import VueEcharts from 'vue-echarts'

const props = defineProps<{
  data: any[]
}>()

const designStore = useDesignStore()
const option = computed(() => {
  // echarts 饼图option
  return {
    tooltip: {
      trigger: 'item',
    },
    legend: {
      orient: 'horizontal',
      left: 'center',
      bottom: 20,
    },
    series: [
      {
        name: '',
        type: 'pie',
        radius: '60%',
        center: ['50%', '50%'],
        label: {
          show: false,
        },
        data: props.data,
      },
    ],
  }
})

const chartRef = ref<VChartInstance>()

useChartAutoResize(chartRef)
</script>

<template>
  <VueEcharts
    ref="chartRef"
    :option="option" :init-options="{
      locale: 'zh',
    }" :theme="designStore.theme"
  />
</template>
